
var ItemJson={};//货品详情
var supplierJson={};//供应商详情
var imgs;
var supplier;
var app_url=location.origin;
var MOBILE=true;
var TEAM=0;
var PlaceOrder=false;//代下单
var imgArray=[];//大图数组
var typeNo_id=0;
var styleNo_id=""; //款号
var styleData=""; //存入款号的值
var isLogin=getcookie("CustomerID");//客户ID
(function(){
    //var inlayID= inlay_id;
    var item = null;
    var inlayItem={
        init:function(){
            args = GetUrlParms();
            if(args["ID"]!=undefined){
                inlaysettingsID = args["ID"];//产品ID
            }
            if(args["team"]!=undefined){
                TEAM=args["team"];//2为现货
            }
            if(args["cid"]!=undefined){
                Customer_id = args["cid"];
                PlaceOrder=true;//代下单
            }

            if(args["typeNo"]!=undefined){
                typeNo_id = args["typeNo"];
            }

            if(args["styleNo"]!=undefined){
                styleNo_id = args["styleNo"];
            }



            this.bindEvent();
            this.loadInlayItem();

            this.loadStyleInlayItem();
        },
        bindEvent:function(){
            var self=this;
            if(APP){
                if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                    $("#add_list").hide();
                }
            }
            //立即购买
            $("#edit_btn_box").on("click","#add_to_order",function(){
                var orderJson={};
                orderJson.orderID = [];
                orderJson.type="inlays";
                orderJson.PriceUSD=$("#dataUSD").text();
                orderJson.PriceRMB=$("#dataRMB").text();


                orderJson.orderID.push(inlaysettingsID);
                if(PlaceOrder==true){
                    var link_url="/Customer/SubmitDiaOrder?type=7&cid="+Customer_id+'&userName='+NullFormat(getUrlParam('userName'));
                }else{
                    var link_url="/Customer/SubmitDiaOrder?type=7";
                }
                if(APP){
                    var appJson={};
                    appJson.title="确认下单";
                    appJson.url=app_url+link_url;
                    appJson.content=JSON.stringify(orderJson);
                    YiYi_APP.submitOrder(JSON.stringify(appJson))
                }else{
                    var action=link_url;
                    form = $("<form method='post' id='params_form' action='"+action+"'>"+
                        "<input type='text' value='"+JSON.stringify(orderJson)+"' name='params'></form>")
                    $("#form_box").html(form);
                    $("#params_form").submit();
                }
            });


            //删除产品
            $("#edit_btn_box").on("click","#inlay_delete",function(){
                myApp.confirm('您确定要删除该货品吗？', function () {
                    self.DelInlays();
                });
            });

            //app编辑
            $("#edit_btn_box").on("click","#edit_btn",function(){
                var url=$(this).attr("data-href");
                //var title=$("#app_title").text();
                if(APP){
                    var editJson={};
                    editJson.url=app_url+url;
                    editJson.title="空托编辑";
                    YiYi_APP.editGoods(JSON.stringify(editJson));
                }else{
                    location.href=url;
                }
            });
            //加入购物车
            $("#edit_btn_box").on("click","#add_to_cart", function () {
                var inlaysettingsId = $(this).attr("data-id");
                self.AddCart(inlaysettingsId);
            });
            //继续逛逛
            $(".page").on("click","#go_shop",function(){
                var linkUrl="/Customer/inlaysettings?team=0";
                $("#cart-tip").remove();
                if(APP){
                    YiYi_APP.finish();
                }else{
                    location.href=linkUrl;
                }
            });
            //去购物车
            $(".page").on("click","#go_cart",function(){
                var linkUrl="/Customer/InlaySettingsCart";
                $("#cart-tip").remove();
                if(APP){
                    var appJson={};
                    appJson.title="购物车";
                    appJson.function_menu="shopping_cart";
                    appJson.url=app_url+linkUrl;
                    YiYi_APP.showExistingPage(JSON.stringify(appJson));
                }else{
                    location.href=linkUrl;
                }
            });
            //跳到证书
            $("#inlays_detail").on("click","a.cert_link_btn",function(){
                var link_url=$(this).attr("data-href");
                if(APP){
                    var appJson={};
                    appJson.title="证书";
                    appJson.url=app_url+link_url;
                    YiYi_APP.showNewPage(JSON.stringify(appJson));
                }else{
                    location.href=link_url;
                }
            });

            //相同款号
            $("#inlaysettings_detail").on('click','#styleNo',function(){
                myApp.popup(".inlaysettings_box");
                if(TEAM ==1 || TEAM ==2){
                   $('.add_inlaysettings_buy').hide();
                   $('.operation').hide();
                }
                $("#styleNo_tbody").html('');
                var str="";
                for(var i=0;i<styleData.length;i++){
                    var row=styleData[i];
                    var status=row.Status;
                    str+='<tr >'+
                        '<td>' +GetText("inlaysettings",1, row.Material, "Material")+ '</td>'+
                        '<td>'+row.Measurement+'</td>'+
                        '<td>'+formatRMBPrice(row.Price)+'</td>'+
                        '<td>'+row.MainWeight+'</td>';
                    if(TEAM ==0 || TEAM ==3){
                        if(status == 1){
                            str+='<td><input type="checkbox" class="checkboxs" id="checkOne" lang="'+row.ID+'" style="zoom:150%"></td>';
                        }else{
                            str+='<td></td>';
                        }
                    }

                    str+='</tr>';
                }
                $('#styleNo_tbody').append(str)
            });

            //相同款号立即订购
            $(".inlaysettings_box").on('click','.add_inlaysettings_buy',function(){
                var  params = {};
                var cartlistCb = $("#styleNo_tab tbody input[type='checkbox']:checked"); //tbody中checked的
                var _IDs = "";

                for(var i = 0; i < cartlistCb.length; i++) {
                    if(i == 0)
                        _IDs += cartlistCb[i].lang;
                    else
                        _IDs += "," + cartlistCb[i].lang;
                }

                if(TEAM==0){//客户端
                    params.CustomerID = CustomerID;
                    params.OrderType = 1;
                }else if(TEAM==3){//代下单
                    params.CustomerID = Customer_id;
                    params.OrderType = 2;
                    params.UserID=UserID;
                }
                params.GoodsType=7;
                params.ProductIDs=_IDs;
                if(cartlistCb.length!=0){
                    $.ajax({
                        url: "/Team/SubmitOrderNew", //提交地址
                        type: "POST",//提交方式
                        data: JSON.stringify(params),
                        contentType: "application/json; charset=utf-8",
                        success: function (result) {
                            var _result = eval('(' + result + ')');//eval()解析单个json对象
                            if(_result.msgcode==false){
                                myApp.alert(_(_result.msginfo));
                            }else{
                                var successful=_result.msginfo.Successful; //成功条目
                                var Failed=_result.msginfo.Failed; //失败条目
                                myApp.alert(_("成功条目")+"：" + successful +","+ _("失败条目")+"："  + Failed);
                                $('.inlaysettings_box').hide();
                            }
                        }
                    });

                }else{
                    myApp.alert("请勾选需要勾选的商品")
                }
            });

            //相同款号加入购物车
            $(".inlaysettings_box").on('click','.add_inlaysettings_cart',function(){
                var  params = {};
                var cartlistCb = $("#styleNo_tab tbody input[type='checkbox']:checked"); //tbody中checked的
                var _IDs = "";

                for(var i = 0; i < cartlistCb.length; i++) {
                    if(i == 0)
                        _IDs += cartlistCb[i].lang;
                    else
                        _IDs += "," + cartlistCb[i].lang;
                }
                params.CartType = 1;
                if(TEAM==0){//客户端
                    params.CustomerID = CustomerID;
                }
                params.IDs=_IDs;
                if(cartlistCb.length!=0){
                    $.ajax({
                        url: "/Team/AddInlaySettingsCart", //提交地址
                        type: "POST",//提交方式
                        data: JSON.stringify(params),
                        contentType: "application/json; charset=utf-8",
                        success: function (result) {
                            var _result = eval('(' + result + ')'); //eval()解析单个json对象
                            var successful=_result.succ; //成功条目
                            var Failed=_result.fail; //失败条目
                            myApp.alert(_("成功条目")+"：" + successful +","+ _("失败条目")+"："  + Failed);
                            $('.inlaysettings_box').hide();
                        }
                    });

                }else{
                    myApp.alert("请勾选需要勾选的商品")
                }
            });


        },

        //根据款号加载详情
        loadStyleInlayItem:function(){
                var submitJson={};
                submitJson.StyleNo=styleNo_id;
                submitJson.GoodsType=7;
                if(TEAM==0){
                    submitJson.CustomerID = CustomerID;//客户ID
                }
                if(TEAM==3){
                    submitJson.CustomerID = Customer_id;
                }
                $.ajax({
                    url: "/Team/GetProductData",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(submitJson),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var res=JSON.parse(result);
                        styleData=res.msginfo.rows; //相同款号所有值
                        for(var i=0;i<styleData.length;i++){
                            $("#inlaysettings_detail #styleNo").html(styleData.length);
                        }
                    }
                });

        },

        //加载详情
        loadInlayItem:function(){
            //myApp.showIndicator();//显示加载中

            var self=this;
            var das=''
            if(APP){
                das=eval('('+YiYi_APP.getProductInfo()+')');
            }else{
                das=eval('('+window.sessionStorage.das+')') || '';
            }
                var submitJson={};
                submitJson.ID=inlaysettingsID;
                submitJson.GoodsType=7;
                if(TEAM == 0){
                    submitJson.CustomerID=CustomerID;
                }
                if(TEAM ==3){
                    submitJson.CustomerID=Customer_id;
                }
                // if(TEAM==0){
                //         submitJson.CustomerID = CustomerID;//客户ID
                //         var requsetProduct={};
                //         requsetProduct.ProductNo=das.productno;
                //         requsetProduct.ProductSupplier=das.productsupplier;
                //         requsetProduct.CustomerID=CustomerID;
                //         requsetProduct.GoodsType=7;
                //         $.ajax({
                //             url: "/Customer/ProductSearch",//提交地址
                //             type: "POST",//提交方式
                //             data: JSON.stringify(requsetProduct),
                //             contentType: "application/json; charset=utf-8",
                //             success: function (result) {
                //
                //             }
                //         });
                //     };

            if(TEAM==2){
                submitJson.IsMyStock=true;
            }
            $.ajax({
                url:'/Team/GetProductData',
                type:'POST',
                data: JSON.stringify(submitJson),
                dataType:'JSON',
                contentType: "application/json; charset=utf8",
                timeout: 30000, //超时时间：30秒
                success:function(result){
                    var res=eval('(' + result + ')');
                    ItemJson=res;
                    if (res.msgcode == true) {
                        var datas=res.msginfo.rows;
                        var data =datas[0];
                        //self.LoadSupplierDetail(data.Supplier);
                        imgs = data.Images.split("|");
                        var lis="";
                        var app_lis=[];
                        var span_lis="";
                        var jsonImg={
                            images:[],
                            videos:''
                        }
                        for (var i=0; i< imgs.length;i++) {
                            jsonImg.images.push(imgs[i])
                            if (imgs[i].length > 50) {
                                var span_li='<span data-val="'+i+'"></span>';
                                span_lis+=span_li;
                                var li = '<li><a href="'+imgs[i] +'"><img src="' + imgs[i] + '" class="image' + i + '"/></a></li>';
                                lis += li;
                                var big = imgs[i].replace('800x800', '1920x1920');
                                var app_li={url: imgs[i], caption: i};
                                app_lis.push(app_li);
                                imgArray.push(big);
                            }else{
                                var img_null='/images/no_img.jpg';
                                var lis='<li><a href="/images/no_img.jpg"><img src="'+img_null+'" class="image' + i + '"/></a></li>';
                                var app_li={url: img_null, caption: i};
                                app_lis.push(app_li);
                                imgArray.push(img_null)
                            }
                        }
                        //图片列
                        // var userAgent=navigator.userAgent;
                        // if(APP && userAgent.indexOf('Android')!=-1){
                        //     YiYi_APP.showRotationChart(JSON.stringify(jsonImg))
                        //     $("#MainContent").hide();
                        // }else{
                            $("#img_box").html(lis);
                            $("#Indicators").html(span_lis);
                            if(MOBILE){
                                (function(window, Util, PhotoSwipe){
                                    document.addEventListener('DOMContentLoaded', function(){
                                        var options = {},
                                            instance = PhotoSwipe.attach( window.document.querySelectorAll('.ps-carousel-item img'), options );
                                    }, false);
                                    Util.Events.domReady(function(e){
                                        var instance, indicators;
                                        instance = PhotoSwipe.attach(
                                            app_lis,
                                            {
                                                target: window.document.querySelectorAll('#PhotoSwipeTarget')[0],
                                                preventHide: true,
                                                getImageSource: function(obj){
                                                    return obj.url;
                                                },
                                                getImageCaption: function(obj){
                                                    return obj.caption;
                                                }
                                            }
                                        );
                                        indicators = window.document.querySelectorAll('#Indicators span');
                                        instance.addEventHandler(PhotoSwipe.EventTypes.onDisplayImage, function(e){
                                            var i, len;
                                            for (i=0, len=indicators.length; i<len; i++){
                                                indicators[i].setAttribute('class', '');
                                            }
                                            indicators[e.index].setAttribute('class', 'current');
                                        });
                                        instance.show(0);
                                    });
                                }(window, window.Code.Util, window.Code.PhotoSwipe))
                            }
                            //显示图片end

                        // }

                        //显示视频
                        $('#video_div').find('video').attr('src',data.Videos)
                        $('#video_div').find('.zy_wrap').css('height','250px')



                        //详情参数
                        // LoadInlaySettingsItemHtml(data);
                        //详情参数
                        var totalPrice=(parseFloat(data.GoldPrice)*parseFloat(data.NetGoldWeight)*(1+parseFloat(data.Wastage)))+parseFloat(data.SidePrice)+parseFloat(data.LaborFee)+parseFloat(data.Insurance)+parseFloat(data.SideLaborFee*data.SideNum)    //金价*总重*（1+损耗）+副石金额+工费+保险费+副石工费*副石数

                        var DiscountPrice=""; //总价和优惠价
                        if(TEAM==0){
                            if(RMBInlaySettingsPrice_td_new == true){
                                DiscountPrice= '<div class="tr">'+
                                    '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color">'+formatRMBPrice(data.Price)+'</div>'+
                                    '</div>'
                            }
                            if(discountInlaySettingsRMBPrice_td_new == true){
                                DiscountPrice+='<div class="tr">'+
                                    '<div class="td td_str">'+_("优&nbsp;&nbsp;惠&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color">'+formatRMBPrice(data.Price*Discounts)+'</div>'+
                                    '</div>';
                            }

                        }else{
                            if(TEAM == 3){
                                DiscountPrice= '<div class="tr">'+
                                    '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color">'+formatRMBPrice(data.Price)+'</div>'+
                                    '</div>'
                            }else{
                                DiscountPrice= '<div class="tr">'+
                                    '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color">'+formatRMBPrice(totalPrice)+'</div>'+
                                    '</div>'
                            }

                        }

                        var videoStr='';
                        if(data.Videos){
                            videoStr= '<div class="td td_str"><img src="/images/imageIcon.png" class="ImgBtn" style="width:20px;height:20px;cursor: pointer;margin-right:15px"></div>';
                            videoStr+='<div class="td td_data"><img src="/images/videoIcon.png" data-videos="'+data.Videos+'" class="VideoBtn" style="width:20px;height:20px;cursor: pointer"></div>';
                        }

                        var strLaborFee="";  //工费
                        var strWastage="";//损耗
                        var strSideLaborFee=""; //副石工费
                        var strSidePrice=""; //副石额
                        if(TEAM==1 || TEAM==2){
                            strLaborFee= data.LaborFee;
                            strWastage=(data.Wastage*100).toFixed(0);
                            strSideLaborFee=data.SideLaborFee;
                            strSidePrice=data.SidePrice;
                        }else{
                            strLaborFee= data.CustomerLaborFee;
                            strWastage=(data.CustomerWastage*100).toFixed(0);
                            strSideLaborFee=data.CustomerSideLaborFee;
                            strSidePrice=data.CustomerSidePrice;
                        }

                        var strStyleNo='';
                        if(TEAM == 0 || TEAM == 1 || TEAM == 2|| TEAM ==3 ){
                            strStyleNo='<div class="td td_data styleNo" id="styleNo" style="padding-left:10px;color:#0080ff;width:20px"></div>';
                        }

                        var countryStr='';
                        if(TEAM == 0){
                            if(placeInlaySettings_td_new == true){
                                countryStr=  '<div class="tr">'+
                                    '<div class="td td_str">'+_("所&nbsp;&nbsp;在&nbsp;&nbsp;地")+'：</div>'+
                                    '<div class="td td_data">'+GetText("inlaysettings",1,data.Country,"Country")+data.State+'</div>'+
                                '</div>'
                            }

                        }else{
                            countryStr=  '<div class="tr">'+
                                '<div class="td td_str">'+_("所&nbsp;&nbsp;在&nbsp;&nbsp;地")+'：</div>'+
                                '<div class="td td_data">'+GetText("inlaysettings",1,data.Country,"Country")+data.State+'</div>'+
                                '</div>'
                        }

                        var gems_detail=[
                            '<div class="detail_left">',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("系列名称")+'：</div>',
                            '<div class="td td_data" id="app_title">',data.Series,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("款&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号")+'：</div>',
                            '<div class="td td_data">',data.StyleNo,'</div>',
                                strStyleNo,
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重")+'：</div>',
                            '<div class="td td_data">',data.TotalWeight,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("工&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;费")+'：</div>',
                            '<div class="td td_data">',strLaborFee,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("损&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;耗%")+'：</div>',
                            '<div class="td td_data">',strWastage,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("厂&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;家")+'：</div>',
                            '<div class="td td_data">',data.Manufactor,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("尺&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;寸")+'：</div>',
                            '<div class="td td_data">',data.Measurement,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态")+'：</div>',
                            '<div class="td td_data">',GetText("inlaysettings",1,data.Status,"Status"),'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("出售方式")+'：</div>',
                            '<div class="td td_data">',GetText("inlaysettings",1,data.IsStock,"IsStock"),'</div>',
                            '</div>',
                            '</div>',


                            '<div class="detail_right">',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号")+'：</div>',
                            '<div class="td td_data">',data.OriginSN,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质")+'：</div>',
                            '<div class="td td_data">',GetText("inlaysettings",1,data.Material,"Material"),'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("主石重量")+'：</div>',
                            '<div class="td td_data">',data.MainWeight,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("副石重量")+'：</div>',
                            '<div class="td td_data">',data.SideWeight,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("副石粒数")+'：</div>',
                            '<div class="td td_data">',data.SideNum,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("副石工费")+'：</div>',
                            '<div class="td td_data">',strSideLaborFee,'</div>',
                            '</div>',
                            '<div class="tr">',
                            '<div class="td td_str">'+_("副石总价")+'：</div>',
                            '<div class="td td_data">',strSidePrice,'</div>',
                            '</div>',
                            countryStr,
                            '<div class="tr">',
                                videoStr,
                            '</div>',
                            '</div>',

                            '<div class="tr tr_block tr_normal">',
                            '<div class="td td_str">'+_("备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注")+'：</div>',
                            '<div class="td td_data">',data.Remark,'</div>',
                            '</div>',
                            '<div class="tr tr_block  tr_normal">',
                            '<div class="td td_str">'+_("上传时间")+'：</div>',
                            '<div class="td td_data">', DateTimeFormat(data.InsertTime), '</div>',
                            '</div>',
                            '</div>',
                            DiscountPrice,
                        ].join('');

                        $("#inlaysettings_detail").html(gems_detail);

                        //管理页面有编辑和删除按钮
                        var addCart;
                        if(typeNo_id==0){
                            addCart='';
                        }else{
                            if(APP){
                                if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                                    addCart="";
                                }else{
                                    addCart= '<a href="#" style="margin-right:20px;" id="add_to_cart" data-id='+data.ID+'>加入购物车</a>'
                                }
                            }else{
                                addCart= '<a href="#" style="margin-right:20px;" id="add_to_cart" data-id='+data.ID+'>加入购物车</a>'
                            }
                        }
                        if(APP){
                            if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                                var editHtmlStr= [].join('');
                            }else{
                                if(data.Status==1 || data.Status==3 || data.Status==6){
                                    var editHtmlStr= [
                                        addCart,
                                        '<a href="#" id="add_to_order">立即购买</a>'].join('');
                                }else{
                                    var editHtmlStr=['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                                }
                            }
                        }else{
                            if(data.Status==1 || data.Status==3 || data.Status==6){
                                var editHtmlStr= [
                                    addCart,
                                    '<a href="#" id="add_to_order">立即购买</a>'].join('');
                            }else{
                                var editHtmlStr=['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                            }
                        }


                        if(data.Status==1 || data.Status==3 || data.Status==6){
                            var placeHtmlStr= ['<a href="#" id="add_to_order">'+_("代购买")+'(<b style="font-size:12px" id="_realName">'+getUrlParam('userName')+'</b>)'+'</a>'].join('');
                        }else{
                            var placeHtmlStr= ['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                        }

                        var myEditHtml=[
                            '<a href="#" id="edit_btn" data-href="/Team/InlaySettingsManagement?ID=',data.ID,'&type=7" style="margin-right:20px;">编辑</a>',
                            '<a id="inlay_delete" href="#">删除</a>'].join('');
                        if(TEAM==0 ){//客户端的列表页
                            $("#edit_btn_box").html(editHtmlStr);
                        }else if(TEAM==2){//现货
                            $("#edit_btn_box").html(myEditHtml);

                        }else if(TEAM==3){//代下单
                            $("#edit_btn_box").html(placeHtmlStr);
                        }
                        //   @*主题色start*@
                        $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
                        //  @*主题色end*@
                        item = res;
                        //放大图片
                        // console.log(imgArray)
                        var myPhotoBrowserStandalone = myApp.photoBrowser({
                            photos : imgArray,
                            backLinkText: '返回',
                            ofText:"/",
                        });
                        $$('#look_img').on('click',function () {
                            var index=$("#Indicators").find("span.current").index();
                            if(APP){
                                var ProductImg={};
                                ProductImg['images']=imgArray;
                                ProductImg['index']=index;
                                YiYi_APP.showImages(JSON.stringify(ProductImg));
                            }else{
                                myPhotoBrowserStandalone.open();
                            }
                        });


                    }else{
                        myApp.alert(res.result);
                    }
                    myApp.hideIndicator();//隐藏加载中
                },
                error:function(a,b,c){
                    myApp.alert(c);
                }
            });
        },

        //刪除成品
        DelInlays:function() {
            myApp.showIndicator();//显示加载中
            $.ajax({
                url: "/Team/DelProductData",//提交地址
                type: "POST",//提交方式
                data: "{'id':'" +inlaysettingsID + "','GoodsType':'7'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var jsonResult = eval('(' + result + ')');//eval()解析单个json对象
                    if (jsonResult && jsonResult.result) {
                        myApp.alert('删除成功！', function () {
                            if(APP){
                                var appJson={};
                                appJson.isReFreshList=true;
                                YiYi_APP.refresh(JSON.stringify(appJson));
                                YiYi_APP.finish();
                            }else{
                                location.href = "/Team/MyInlaySettings?team=2";
                            }
                        });
                    } else {
                        myApp.alert(jsonResult.msg);
                    }
                    myApp.hideIndicator();//隐藏加载中
                }
            });
        },
        //加入购物
        AddCart:function (inlaysettingsId) {
            //InventoryIDs值组装 _inventoryIDs="232,324"
            myApp.showPreloader('正在加入中，请稍等...');
            var addCart = {};
            addCart.CustomerID = CustomerID;
            addCart.CartType = 1;
            addCart.IDs = inlaysettingsId;
            $.ajax({
                url: "/Team/AddInlaySettingsCart",//提交地址   /customer/ringcart
                type: "POST",//提交方式
                data: JSON.stringify(addCart),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var res=eval('('+result+')');
                    myApp.hidePreloader();
                    if(res.msgcode==true){
                        var strTip = "";
                        strTip = '<div class="tip-box order-tip" id="cart-tip">'+
                            '<div class="tip-text">'+
                            '<div class="tip-title">'+
                            '<div class="">加入购物车成功</div>'+
                            '</div>'+
                            '<div class="buttons">'+
                            '<span class="btn-left" id="go_shop"><a href="#">继续逛逛</a></span>'+
                            '<span class="btn-right" id="go_cart"><a href="#">去购物车</a></span>'+
                            '</div>'+
                            '</div>'+
                            '</div>';
                        $("#app_no_header").after(strTip);
                        $(".tip-box").show();
                        //   @*主题色start*@
                        $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
                        //  @*主题色end*@
                    }else{
                        myApp.alert(res.msginfo);
                    }
                }
            });
        },

    }
    inlayItem.init();

}());



//现货查看采购美金和人民币的转换
function returnPurUSDPrice(data){
    return formatUSDPrice(data.PurchaseUSD);
}
function returnPurRMBPrice(data){
    return formatRMBPrice(data.PurchaseRMB);
}



//app分享用的详情
function Item_APP(){
    if(APP){
        var shareJson={};
        shareJson.title="成品"+GetCategory(ItemJson.Category);
        shareJson.text="颜色"+"："+GetText(ItemJson.Category,ItemJson.MainColor,"MainColor")+"；"+"形状"+"："+GetText(ItemJson.Category,ItemJson.MainShape,"MainShape")+"；"+
            "主石重量"+"："+ItemJson.MainWeight+"；"+("价格")+"："+ItemJson.Price+"；"+("类型")+"："+GetText(ItemJson.Category,ItemJson.Type,"Type")+"；"+
            "风格款式"+"："+GetText(ItemJson.Category,ItemJson.Style,"Style")+"；"+"材质"+"："+GetText(ItemJson.Category,ItemJson.Material,"Material")+"；"+("出售方式")+"："+GetText(ItemJson.Category,ItemJson.IsStock,"IsStock");
        imgs = ItemJson.Images.split("|");
        shareJson.images=[];
        for (var i=0; i< imgs.length;i++) {
            if (imgs[i].length > 10) {
                shareJson.images.push(imgs[i]);
            }
        }
        shareJson.url=app_url+"/"+LANGCODE+"/inlays/"+ItemJson.ID;
        shareJson.copy_text=shareJson.text;
        YiYi_APP.share(JSON.stringify(shareJson));
    }
}
//带链接的证书类型
function linkCertType(data) {
    var certLink="-";
    if (data.MainCertNo) {
        if (data.MainCertType == "GIA" || data.MainCertType == "IGI") {
            certLink="<a  class='cert_link_btn' href='#' data-href='/team/ViewCert?certType=" + data.MainCertType + "&certNo=" + data.MainCertNo + "' title='证书查询" + data.MainCertNo + "'>" + data.MainCertNo  + "</a>";
            // certLink='<a class="inlays_link" href="/cert/' + data.CertType.toLowerCase() + '/' + data.MainCertNo + '" target="_blank">'+data.MainCertNo+'</a>';
        }

    }
    return certLink;

}
//app证书链接
function app_linkCert(){
    var data=ItemJson;
    var App_json={};
    App_json.certType=data.MainCertType;
    App_json.certNumber=data.MainCertNo;
    App_json.url="http://apitest.checkgems.com:8200/api/v2/certs/"+data.MainCertType+"/"+data.MainCertNo;
    App_json.pdfUrl="http://apitest.checkgems.com:8200/api/v2/certs/"+data.MainCertType+"/"+data.MainCertNo+".pdf";
    YiYi_APP.showCertificate(JSON.stringify(App_json));
}

//付款
function formatReceiptStatus(val){
    if(val==0){
        return _("未支付");
    }else if(val==1){
        return _("已支付");
    }
}

//点击视频
var userAgent=navigator.userAgent;
$("#inlaysettings_detail").on('click','.VideoBtn',function(){

   if(APP && userAgent.indexOf('Android')!=-1){
        // $("#video_div").show().css("display","none");
        $("#video_div").show().css("display","block");
   }else{
       $("#video_div").show().css("display","block");
   }
    $('#MainContent').hide();
    $("#look_img").hide();
    if(APP){
        var ProductVideo={};
        ProductVideo.url = $(this).attr('data-videos');
        YiYi_APP.showVideo(JSON.stringify(ProductVideo));
    }

})

// 点击图片icon
$("#inlaysettings_detail").on("click",".ImgBtn",function(){
    if(APP && userAgent.indexOf('Android')!=-1){
        // $('#MainContent').hide();
        $('#MainContent').show();
    }else{
        $('#MainContent').show();
    }

    $("#look_img").show();
    $("#video_div").hide();

});






